package com.hollycrm.ahunicom.sheet.business.web;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.hollycrm.ahunicom.sheet.business.OperationRecord;
import com.hollycrm.ahunicom.sheet.business.OperationRecordDao;
import com.hollycrm.springframework.web.struts.DispatchActionSupport;
import com.hollycrm.unicom.sheet.BeanResource;
import com.hollycrm.unicom.sheet.Constants;
import com.hollycrm.unicom.sheet.business.BusinessManager;
import com.hollycrm.unicom.sheet.business.BusinessSupportManager;


public class ListDealSheetAction extends DispatchActionSupport {
    /**
     * execMainSheet
     *
     * @param mapping ActionMapping
     * @param actionForm ActionForm
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @throws Exception
     * @return ActionForward
     */
    public ActionForward execMainSheet(ActionMapping mapping,
                                     ActionForm actionForm,
                                     HttpServletRequest request,
                                     HttpServletResponse response) throws
        Exception {
        /*String mainSheetFlowNO = request.getParameter("sheetFlowNO");
        String archive = request.getParameter("archive");
        BusinessSupportManager bsm = getBusinessSupportManager(archive);
        List dealSheets = bsm.listDealSheets(mainSheetFlowNO);
        request.setAttribute("dealSheets", dealSheets);
        if (mainSheetFlowNO.startsWith(AhConstants.MAINDEALSHEET_PREFIX)) {
        	return mapping.findForward("successF2");
        } else {*/
    	String  status=(String)request.getParameter("status")==null ? "":(String)request.getParameter("status");
    			request.setAttribute("status", status);
    			List resultRecord = new ArrayList();
    			OperationRecordDao operationRecordDao = (OperationRecordDao)getBean("OperationRecordDao");
    			resultRecord = operationRecordDao.getResultRecord(request.getParameter("sheetFlowNO"));
    			request.setAttribute("resultRecord", resultRecord);
        	return mapping.findForward("success");
      //  }	
    }

    /**
     * execDealSheet
     *
     * @param mapping ActionMapping
     * @param actionForm ActionForm
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @throws Exception
     * @return ActionForward
     */
    public ActionForward execDealSheet(ActionMapping mapping,
                                     ActionForm actionForm,
                                     HttpServletRequest request,
                                     HttpServletResponse response) throws
        Exception {
        String sheetFlowNO = request.getParameter("sheetFlowNO");
        String archive = request.getParameter("archive");
        BusinessSupportManager bsm = getBusinessSupportManager(archive);
//        List dealSheets = bsm.listDealSheets(sheetFlowNO, false);
//        request.setAttribute("dealSheets", dealSheets);
        
        BusinessManager bm= (BusinessManager) getBean(BeanResource.BUSINESS_MANAGER);
        List audits=bm.getAuditMessageList(sheetFlowNO);
        request.setAttribute("audits", audits);
        
        return mapping.findForward("success");
    }

    /**
     * getBusinessSupportManager
     *
     * @param archive String
     * @return BusinessSupportManager
     */
    private BusinessSupportManager getBusinessSupportManager(String archive) {
        if (Constants.TRUE.equals(archive))
            return (BusinessSupportManager) getBean(BeanResource.
                ARCHIVEBUSINESSSUPPORT_MANAGER);
        else
            return (BusinessSupportManager) getBean(BeanResource.
                BUSINESSSUPPORT_MANAGER);
    }

}
